package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.IWmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
public class WmChannelController {
    @Autowired
    private IWmChannelService wmChannelService;

    /**
     * 自媒体端,查询所有频道接口
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult findAll(){
        return wmChannelService.findAll();
    }

    /**
     * 后台管理端新增频道
     * @param wmChannel
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel) {
        return wmChannelService.saveChannel(wmChannel);
    }

    /**
     * 后台管理端分页查询频道
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult listChannel(@RequestBody WmChannelDto dto){
        return wmChannelService.listChannel(dto);
    }

    /**
     * 后台管理端,修改频道,及启用禁用
     * @param wmChannel
     * @return
     */
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody WmChannel wmChannel){
        return wmChannelService.updateChannel(wmChannel);
    }

    /**
     * 频道删除,启用状态不能删除
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannel(@PathVariable Integer id){
        return wmChannelService.deleteChannel(id);
    }
}
